<template>
  <div>
    <div>
      <el-button type="primary" @click="dialogFormVisible = true"
        >新建业务类型</el-button
      >
      <el-table :data="tableData" height="650" border style="width: 50%">
        <el-table-column prop="name" label="业务类型名称" width="180">
        </el-table-column>
        <el-table-column prop="createDate" label="创建时间"> </el-table-column>
        <el-table-column fixed="right" label="操作" width="120">
          <template slot-scope="scope">
            <el-button
              @click.native.prevent="deleteRow(scope.$index, tableData)"
              type="text"
              size="small"
            >
              移除
            </el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>

    <!-- 弹出框 -->
    <el-dialog title="业务类型" :visible.sync="dialogFormVisible">
      <el-form :model="form">
        <el-form-item label="业务类型名称" :label-width="formLabelWidth">
          <el-input
            v-model="form.name"
            autocomplete="off"
            placeholder="请输入业务名称"
          ></el-input>
        </el-form-item>
        <el-form-item label="模板导包" :label-width="formLabelWidth">
          <span>import java.util.Map</span>
        </el-form-item>
        <el-form-item label="规则模板" :label-width="formLabelWidth">
          <pre>
            rule "${ruleCode}"
                when
                    $map:Map(${criteria})
                then
                    $map.put("result", ${result});
            end
          </pre>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="add()">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  name: "BusinessRuleTemp",
  data() {
    return {
      form: {
        name: "",
        ruleTempId: "",
      },
      formLabelWidth: "120px",
      dialogFormVisible: false,
      bTypeName: "",
      tableData: [],
    };
  },
  methods: {
    add() {
      this.$http({
        method: "POST",
        url: "/businessRuleTemp",
        data: {
          name: this.form.name,
          ruleTempId: this.form.ruleTempId,
        },
      }).then((resp) => {
        if (resp.data.code === 200) {
          this.dialogFormVisible = false;
          this.$message({
            message: resp.data.msg,
            type: "success",
          });
          this.select();
        } else {
          this.$message.error(resp.data.msg);
        }
      });
    },
    select() {
      this.$http({
        method: "GET",
        url: "/businessRuleTemp",
      }).then((resp) => {
        if (resp.data.code === 200) {
          this.tableData = resp.data.data;
        } else {
          this.$message.error(resp.data.msg);
        }
      });
    },
    deleteRow(index, tableData) {
      this.$http({
        method: "POST",
        url: "/businessRuleTemp/del",
        params: {
          id: tableData[index].id,
        },
      }).then((resp) => {
        if (resp.data.code === 200) {
          this.select();
        } else {
          this.$message.error(resp.data.msg);
        }
      });
    },
  },
  mounted() {
    this.select();
  },
};
</script>
<style scoped>
.button--text {
  color: #409eff;
  font-size: 12px;
  line-height: 1;
  white-space: nowrap;
  cursor: pointer;
  text-align: center;
  font-weight: 500;
}
</style>